package org.sith.taskrunner.gwt.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import org.sith.taskrunner.gwt.client.services.taskrunner.TaskRunnerService;

import java.util.Map;


public class RunTaskWidget extends Composite {
    interface RunTaskWidgetUiBinder extends UiBinder<VerticalPanel, RunTaskWidget> {
    }

    private static RunTaskWidgetUiBinder ourUiBinder = GWT.create(RunTaskWidgetUiBinder.class);
    @UiField
    ListBox listBox;

    public RunTaskWidget() {
        initWidget(ourUiBinder.createAndBindUi(this));
        TaskRunnerService.App.getInstance().getActivatedTasks(new AsyncCallback<Map<String, String>>() {
            @Override
            public void onFailure(Throwable caught) {
                Window.alert("Error during tasks receiving");
            }

            @Override
            public void onSuccess(Map<String, String> result) {
                for (String s : result.keySet()) {
                    listBox.addItem(result.get(s), s);
                }
            }
        });

    }
}